<template>
  <div class="phone-management scroll">
    <el-button
      class="el-button-my"
      type="success"
      icon="el-icon-switch-button"
      @click="managerPhone(1)"
    >手机重启</el-button>
    <el-button
      class="el-button-my"
      type="success"
      icon="el-icon-upload"
      @click="managerPhone(2)"
    >上传日志</el-button>
    <el-button
      class="el-button-my"
      type="success"
      icon="el-icon-delete"
      @click="managerPhone(5)"
    >清除视频缓存</el-button>
  </div>
</template>

<script>
export default {
  name: 'ToolsPhoneManagement',
  data() {
    return {
      wechats: this.$store.getters['conversation/wechats'],
    }
  },
  methods: {
    // 手机操作
    managerPhone(actionNumber) {
      let currentNavs = this.$store.getters['currentNavs']
      let currentWechats = this.$store.getters['currentWechats']
      let wechatId = currentWechats[currentNavs[this.$route.name]]
      //   如果没有选中微信
      if (!wechatId) {
        this.$message({
          message: '请先选择一个微信',
          type: 'warning'
        });
      } else {
        //  命令
        let command = {
          wechatId: wechatId,
          action: actionNumber
        }
        // 微信昵称
        let wechatNick = wechatId
        for (const wechat of this.wechats) {
          if (wechat.WeChatId === wechatId) {
            wechatNick = wechat.WeChatNick
          }
        }
        // 提示
        let tip = {
          1: `微信：${wechatNick}，即将关机？`,
          2: `上传 微信：${wechatNick} 的日志？`,
          5: `清除微信：${wechatNick} 的视频缓存？`
        }

        this.$confirm(tip[actionNumber], '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$store.dispatch('websocket/PhoneActionTask', command)
          this.$message({
            type: 'success',
            message: '指令已经执行!'
          });
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消'
          });
        });
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.phone-management {
  height: 100%;
  display: flex;
  flex-wrap: wrap;
  overflow-y: auto;

  .el-button-my {
    height: 40px;
    min-height: 40px;
    width: 120px;
    padding: 5px;
    margin: 10px;
  }
}
</style>
